﻿using System;
using JSM.DataStore;
using JSM.Test.MockUp;

namespace JSM.Test
{
	public static class UnitTestHelper
	{
		public static void TestFunctionWithDefaultDataStore(Action<IJavaScriptModelAware, IDataStoreProvider> dunctionToExecute)
		{
			DefaultDataStoreFactory.UnregisterAllDefaultDataStores();
			DefaultDataStoreFactory.RegisterDefaultDataStore(typeof(UnitTestJavaScriptAware), unitTestJavaScriptAware => ((UnitTestJavaScriptAware)unitTestJavaScriptAware).UnitTestDataStoreProvider);

			UnitTestJavaScriptAware javaScriptModelAware = new UnitTestJavaScriptAware();

			dunctionToExecute(javaScriptModelAware, null);
		}

		public static void TestFunctionWithoutDefaultDataStore(Action<IJavaScriptModelAware, IDataStoreProvider> functionToExecute)
		{
			DefaultDataStoreFactory.UnregisterAllDefaultDataStores();

			UnitTestJavaScriptAware javaScriptModelAware = new UnitTestJavaScriptAware();
			IDataStoreProvider dataStoreProvider = new UnitTestDataStoreProvider();

			functionToExecute(javaScriptModelAware, dataStoreProvider);
		}
	}
}
